<?php

namespace app\common\model;

use think\Cache;
use think\Model;

/**
 * 消息
 */
class Sysmessage extends Model
{


    protected $table = 'fa_sysmessage';
    
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    
    public function getCreatetimeAttr($value)
    {   
        if(!empty($value)){
            return date('Y-m-d H:i:s',$value);
        }
        return '';
    }


    /**
     * 添加消息记录
     *
     * @param [type] $user_id
     * @param [type] $title
     * @param [type] $sub_title
     * @param [type] $content
     * @return void
     */
    public static function addLog($user_id,$title,$sub_title='',$content=''){

        $data = [];
        $data['user_id']    = $user_id;
        $data['title']      = $title;
        $data['sub_title']  = $sub_title ?? $title;
        $data['content']    = $content;
        self::create($data);
    }
}
